package 第二十章项目.clothesSystem.wrap;

public class MyAnnotationProcessor {
    public static PersonBean createBeanFromAnnotation(Class <?> clazz){
        if(clazz.isAnnotationPresent(MyAnnotation.class)){
            MyAnnotation annotation= clazz.getAnnotation(MyAnnotation.class);
            PersonEnum person_enum =annotation.value();
            return createBeanFromEnum(person_enum);
        }
        throw new IllegalArgumentException("Class is not annotated with @MyAnnotation");
    }

    private static PersonBean createBeanFromEnum(PersonEnum personEnum){
        String name=personEnum.getProperty("NAME");
        String ageStr=personEnum.getProperty("AGE");
        String sex=personEnum.getProperty("SEX");
        int age=Integer.parseInt(ageStr);
        return new PersonBean(name,age,sex);
    }
}
